package ru.nsu.effel.actions;

import javax.servlet.http.HttpSession;

import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.action.ActionBeanContext;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;
import ru.nsu.effel.persistence.ConnectionBid;
import ru.nsu.effel.persistence.ConnectionBidManager;

public class FitterProfileActionBean implements ActionBean {
	private ActionBeanContext context;
	private int[] bidIds;

	public int[] getBidIds() {
		return bidIds;
	}

	public void setBidIds(int[] bidIds) {
		this.bidIds = bidIds;
	}

	public ActionBeanContext getContext() {
		return context;
	}

	public void setContext(ActionBeanContext context) {
		this.context = context;
	}
	
	public Resolution confirmConnectionBids() {
		HttpSession session = getContext().getRequest().getSession(false);
		Integer fitterId = (Integer)session.getAttribute("accountId");
		for(int i = 0; i <bidIds.length; i++) {
			ConnectionBid bid = ConnectionBidManager.getInstance().getConnectionBidById(bidIds[i]);
			bid.setBidStatus(3);
			ConnectionBidManager.getInstance().updateConnectionBid(bid);
		}
		ConnectionBidManager.getInstance().deleteConnectionBidsFromFitter(fitterId, bidIds);
		return new ForwardResolution("/FitterProfile.jsp");
	}
}